package com.javatip.project.main.controller;

import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import oshi.SystemInfo;
import oshi.hardware.CentralProcessor;
import oshi.hardware.GlobalMemory;
import oshi.hardware.HardwareAbstractionLayer;
import oshi.hardware.GraphicsCard;
import oshi.hardware.Sensors;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


//可以在前端加个按钮每次自动提交请求，实现实时刷新
@Component
public class ConsoleInterceptor {
    public String print() {
        // 创建一个字节数组输出流
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        // 将标准输出流重定向到字节数组输出流
        System.setOut(new PrintStream(outputStream));
        String consoleOutput = "";
        for (int i = 0; i < 1000; i++) {
            System.out.println("Hello, world!");

            // 在控制台输出一些内容
            System.out.println("Hello, world!");
            System.out.println("This is a test.");

            // 获取控制台输出内容
            consoleOutput = outputStream.toString();
        }
        // 输出获取到的控制台内容
//        System.out.println("Console Output:");
//        System.out.println(consoleOutput);
        return consoleOutput;
    }

}
